 package uk.co.mmscomputing.device.twain;
 
 import java.awt.GridLayout;
 import java.awt.event.ActionListener;
 import java.beans.EventHandler;
 import java.io.PrintStream;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComponent;
 import uk.co.mmscomputing.device.scanner.Scanner;
 import uk.co.mmscomputing.device.scanner.ScannerIOException;
 import uk.co.mmscomputing.device.scanner.ScannerIOMetadata;
 import uk.co.mmscomputing.device.scanner.ScannerIOMetadata.Type;
 import uk.co.mmscomputing.device.scanner.ScannerListener;
 import uk.co.mmscomputing.util.JarImageIcon;
 
 public class TwainPanel extends JComponent
   implements TwainConstants, ScannerListener
 {
   Scanner scanner = null;
   JButton acqbutton = null;
   JButton selbutton = null;
   JCheckBox guicheckbox = null;
 
   public TwainPanel(Scanner paramScanner, int paramInt)
     throws TwainIOException
   {
     this.scanner = paramScanner;
 
     switch (paramInt) {
     case 0:
       this.acqbutton = new JButton("acquire");
       this.selbutton = new JButton("select");
       setLayout(new GridLayout(0, 1));
       break;
     case 1:
       this.acqbutton = new JButton("acquire");
       this.selbutton = new JButton("select");
       setLayout(new GridLayout(1, 0));
       break;
     case 2:
       this.acqbutton = new JButton("acquire", new JarImageIcon(getClass(), "16x16/scanner.png"));
       this.selbutton = new JButton("select", new JarImageIcon(getClass(), "16x16/list.png"));
       setLayout(new GridLayout(0, 1));
       break;
     case 3:
       this.acqbutton = new JButton("acquire", new JarImageIcon(getClass(), "16x16/scanner.png"));
       this.selbutton = new JButton("select", new JarImageIcon(getClass(), "16x16/list.png"));
       setLayout(new GridLayout(1, 0));
       break;
     case 4:
       this.acqbutton = new JButton("acquire", new JarImageIcon(getClass(), "32x32/scanner.png"));
       this.selbutton = new JButton("select", new JarImageIcon(getClass(), "32x32/list.png"));
       setLayout(new GridLayout(0, 1));
       break;
     case 5:
       this.acqbutton = new JButton("acquire", new JarImageIcon(getClass(), "32x32/scanner.png"));
       this.selbutton = new JButton("select", new JarImageIcon(getClass(), "32x32/list.png"));
       setLayout(new GridLayout(1, 0));
     }
 
     this.acqbutton.addActionListener((ActionListener)EventHandler.create(ActionListener.class, this, "acquire"));
     add(this.acqbutton);
 
     this.guicheckbox = new JCheckBox("Enable GUI");
     this.guicheckbox.setSelected(true);
     add(this.guicheckbox);
 
     this.selbutton.addActionListener((ActionListener)EventHandler.create(ActionListener.class, this, "select"));
     add(this.selbutton);
 
     paramScanner.addListener(this);
 
     if (jtwain.getSource().isBusy()) {
       this.acqbutton.setEnabled(false);
       this.selbutton.setEnabled(false);
       this.guicheckbox.setEnabled(false);
     }
   }
 
   public void acquire() {
     try {
       this.scanner.acquire();
     } catch (ScannerIOException localScannerIOException) {
       this.scanner.fireExceptionUpdate(localScannerIOException);
     }
   }
 
   public void select() {
     try {
       this.scanner.select();
     } catch (ScannerIOException localScannerIOException) {
       this.scanner.fireExceptionUpdate(localScannerIOException);
     }
   }
 
   public void update(ScannerIOMetadata.Type paramType, ScannerIOMetadata paramScannerIOMetadata) {
     if ((paramScannerIOMetadata instanceof TwainIOMetadata)) {
       TwainIOMetadata localTwainIOMetadata = (TwainIOMetadata)paramScannerIOMetadata;
       TwainSource localTwainSource = localTwainIOMetadata.getSource();
 
       if (paramType.equals(ScannerIOMetadata.STATECHANGE)) {
         if (localTwainIOMetadata.isState(3))
           if (localTwainSource.isBusy()) {
             this.acqbutton.setEnabled(false);
             this.selbutton.setEnabled(false);
             this.guicheckbox.setEnabled(false);
           } else {
             this.acqbutton.setEnabled(true);
             this.selbutton.setEnabled(true);
             this.guicheckbox.setEnabled(true);
           }
       }
       else if (paramType.equals(ScannerIOMetadata.NEGOTIATE))
         if (localTwainSource.isUIControllable()) {
           localTwainSource.setShowUI(this.guicheckbox.isSelected());
         } else {
           if (!this.guicheckbox.isSelected()) System.out.println("9\bCannot hide twain source's GUI.");
           this.guicheckbox.setSelected(true);
         }
     }
   }
 }

